package cn.edu.njnu.opengmpback.common.utils;

import cn.edu.njnu.opengmpback.Modeling.entity.dto.*;
import cn.edu.njnu.opengmpback.common.dto.PageDTO;
import cn.edu.njnu.opengmpback.resource.entity.dto.ResourcePageDTO;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;


/**
 * @Description
 * @Author wyjq
 * @Date 2022/3/17
 */

@Service
public class CommonService {
    public Pageable getResourcePageable(ResourcePageDTO pageDTO){
        return PageRequest.of(pageDTO.getPage()-1, pageDTO.getPageSize(), Sort.by(pageDTO.getAsc()? Sort.Direction.ASC: Sort.Direction.DESC,pageDTO.getSortField()));
    }
    public Pageable getProjectPageable(ProjectPageDTO pageDTO){
        return PageRequest.of(pageDTO.getPage()-1, pageDTO.getPageSize(), Sort.by(pageDTO.getAsc()? Sort.Direction.ASC: Sort.Direction.DESC,pageDTO.getSortField()));
    }

    public Pageable getConceptMaterialPageable(ConceptMaterialPageDTO pageDTO){
        return PageRequest.of(pageDTO.getPage()-1, pageDTO.getPageSize(), Sort.by(pageDTO.getAsc()? Sort.Direction.ASC: Sort.Direction.DESC,pageDTO.getSortField()));
    }
    public Pageable getConceptModelPageable(ConceptModelPageDTO pageDTO){
        return PageRequest.of(pageDTO.getPage()-1, pageDTO.getPageSize(), Sort.by(pageDTO.getAsc()? Sort.Direction.ASC: Sort.Direction.DESC,pageDTO.getSortField()));
    }
    public Pageable getLogicModelPageable(LogicModelPageDTO pageDTO){
        return PageRequest.of(pageDTO.getPage()-1, pageDTO.getPageSize(), Sort.by(pageDTO.getAsc()? Sort.Direction.ASC: Sort.Direction.DESC,pageDTO.getSortField()));
    }
    public Pageable getLogicMaterialPageable(LogicMaterialPageDTO pageDTO){
        return PageRequest.of(pageDTO.getPage()-1, pageDTO.getPageSize(), Sort.by(pageDTO.getAsc()? Sort.Direction.ASC: Sort.Direction.DESC,pageDTO.getSortField()));
    }
    public Pageable getPageable(PageDTO pageDTO){
        return PageRequest.of(pageDTO.getPage()-1, pageDTO.getPageSize(), Sort.by(pageDTO.getAsc()? Sort.Direction.ASC: Sort.Direction.DESC,pageDTO.getSortField()));
    }
}
